<html>
<head>
<title>库房管理</title>
</head>
<script language="javascript">
var id_db = '0';
	
	function editDpt(id){
	var spid = id.substring(2);
	var urlstr = "__URL__/editDpt?id_tb_depot="+spid;
	var myWindow = function(){
		new MUI.Window({
			id: 'edpdpage',
			title: '修改库房页面',
			loadMethod: 'xhr',
			contentURL: urlstr,
			width: 210,
			height: 210
		});
		}
		myWindow();
	}
	
	function optDpt(id,st){
	var spid = id.substring(2);
	var say ='打开';
	if(st=='open')  {say = '关闭'};

	if(confirm("要" +say+"["+$(spid+'depot_address').innerHTML+" ]的[ "+$(spid+'depot_name').innerHTML+" ]么？"))
     {
		var urlstr = '__URL__/optDepot';
		
		var myRequest = new Request.JSON({
		method: 'post', 
		url: urlstr,
		headers: 'Content-Type:text/html; charset=utf-8',
		data: 'id_depot='+spid+'&status='+st,
		onSuccess: function(data){
		operDptst(data);
		},
		onFailure: function(){
		$('result').set('text', '您的请求失败了.');
		}	
		}).send();
	 }
	}
	
	function operDptst(data){
		if(data[0]['status']=='ok')
		{
		MochaUI.notification(data[0]['msg']);
		window.location.href='__SELF__/?';
		}
		else
		{MochaUI.notification(data[0]['msg']);}
	}	
	
	
	function showForm(){
	var strs = $('form').innerHTML;
	var myWindowad = function(){
		new MUI.Window({
			id: 'adpdpage',
			title: '修改库房页面',
			loadMethod: 'html',
			content: strs,
			width: 210,
			height: 160
		});
		}
		myWindowad();	 
	}
	


	function ShowAddShelfWin(id)
	{	
	var myWindow = function(){
		new MUI.Window({
			id: 'addshelfpage',
			title: '添加库房货架',
			loadMethod: 'xhr',
			contentURL: '__URL__/addShelfwin',
			width: 200,
			height: 170
		});
		}
		myWindow();
		id_db = id;
	}	
	
	function addShlf()
	{
		var myRequest = new Request.JSON({
		method: 'post', 
		url: '__APP__/Depot/addShlf',
		headers: 'Content-Type:text/html; charset=utf-8',
		data: 'describe='+$('describe').value+'&shelf_num='+$('shelf_num').value+'&shelf_layer='
		+$('shelf_layer').value+'&id_tb_depot='+id_db+'&depot_code='+$(id_db+'depot_code').innerHTML,
		onSuccess: function(data){
		operdata(data);
		},
		onFailure: function(){
			$('result').set('text', '您的请求失败了.');
					}	
		}).send(); 		
	}
	
	function operdata(data){
		if(data[0]['status']=='ok')
		{	
		MochaUI.notification('货架记录已经添加');
		$('addshelfpage').dispose();		
		}
		else
		{
		MochaUI.notification(data[0]['msg']);
		}
	}	

function initLoc(id){
id = id.substring(0,id.length-4);
//如果库房货架有记录货更改记录，危险操作，会删除原来所有位置码重新insert
//alert($(id+'it').innerHTML);
if($(id+'it').innerHTML =='false'){
	var urlsrt = 'index.php/Depot/initLoc';
	var datastr='depot_code='+$(id+'depot_code').innerHTML+'&shelf_num='+$(id+'shelf_num').innerHTML+'&shelf_layer='+$(id+'shelf_layer').innerHTML;
	fetchJsonUrl(urlsrt,datastr,opResult);
	}
else
{msg('货架位置码已经初始化了！');}	
}	

</script>  
<body>
<!--主页面开始-->
<div id="maindptPage">
	<!--显示数据列表-->
	<div id="deptList" style="overflow:scroll; text-align:center">
		<!--空记录开始-->
		<if condition="count($deptList) elt 0">
		<h3>没有初始化库房</h3><br>
		<input type="button" name="bt2" value="添加库房" onClick="showForm()">
		</if>
		<!--空记录结束-->	
		<!--数据集显示开始-->
		<if condition="count($deptList) gt 0">
		<h3 style="text-align:center">库房列表</h3>
			<table align="center" bgcolor="#e7efff" width="100%" border="1" cellspacing="1" cellpadding="1" style="font-size:12px;">
		      		<tr>
					    <td colspan="10" align="center" valign="bottom"><input type="button" name="bt2" value="添加库房" onClick="showForm()"></td>
                    </tr>
                    <tr>
                        <td bgcolor="#FF9933">库房id</td>
                        <td bgcolor="#FF9933">库房名称</td>
                        <td bgcolor="#FF9933">库房地址</td>
                        <td bgcolor="#FF9933">库房编码</td>
                        <td bgcolor="#FF9933">库房占用率</td>
						<td bgcolor="#FF9933">库房状态</td>
						<td bgcolor="#FF9933">添加货架</td>						
						<td bgcolor="#FF9933">修改</td>
						<td bgcolor="#FF9933">开/关库房</td>
                    </tr>
						<div id="list" >
                          <volist name="deptList" id="vo">
                            <tr id="{$vo.id_tb_depot}" onMouseOver="this.style.backgroundColor='#f7f7f7'"
							onmouseout="this.style.backgroundColor='transparent'">
							  <td id="{$vo.id_tb_depot}" onClick="list(this.id)">{$vo.id_tb_depot}</td>
							  <td id="{$vo.id_tb_depot}depot_name">{$vo.depot_name}</td>
                              <td id="{$vo.id_tb_depot}depot_address">{$vo.depot_address}</td>                              
                              <td id="{$vo.id_tb_depot}depot_code">{$vo.depot_code}</td>
                              <td id="{$vo.id_tb_depot}occupancy_rate">{$vo.occupancy_rate}</td>
                              <td id="{$vo.id_tb_depot}status">{$vo.status}</td>	
                              <td id="ed{$vo.id_tb_depot}" onClick="ShowAddShelfWin(this.id)"><img src="__PUBLIC__/Images/branch.ico" alt="添加货架"/></td>
                              <td id="ed{$vo.id_tb_depot}" onClick="editDpt(this.id)"><img src="__PUBLIC__/Images/edit.ico" alt="修改库房信息"/></td>
							  <td id="cl{$vo.id_tb_depot}" onClick="optDpt(this.id,'{$vo.status}')"> 
							  <if condition="$vo.status eq 'close'"> 
							  <img src="__PUBLIC__/Images/kai.jpg" alt="打开库房" />
							  <else/>
							  <img src="__PUBLIC__/Images/guan.jpg" alt="关闭库房"/>
							  </if>
							  </td>
                            </tr>
                          </volist>
                        </div>
					<tr>
                    <td align="center" colspan="9">		
					<?php
					if(isset($page)) echo $page;		
					?>	</td>
                    </tr>
		  	</table>
		<!--数据集显示结束-->
		</if>
	</div>
	<!--显示数据列表结束-->
	
	<!--添加数据的form开始-->
	<div id="form" style="display:none">
	<form action="__APP__/Depot/addDepot" method="get" id="formx"><br>
	<input name="id_tb_depot" type="text" value="" id="dpid"  style="visibility:hidden"><br>
	<label>库房名称<input name="depot_name" type="text"  tabindex="1" id="dpname" ></label><br>
	<label>库房地址<input name="depot_address" type="text"  tabindex="2" id="dpadd" ></label><br>
	<label>库房编码<input name="depot_code" type="text"  tabindex="3" id="dpcode" ></label><br>
	<input name="submit" type="submit" id="submit" value="添加库房">
	</form>
	</div>
	<!--添加数据的form结束-->

<!--下面是货架信息-->	

	<!--显示数据列表-->
	<div id="shelfList" style="overflow:scroll; text-align:center">
		<!--空记录开始-->
		<if condition="count($shelfList) elt 0">
		<h3>商家{$Think.session.UserInfo.boss}的库房货架记录为空</h3>
		</if>
		<!--空记录结束-->	
		<!--数据集显示开始-->
		<if condition="count($shelfList) gt 0">
		<h3>拥有货架情况</h3>
			<table align="center" bgcolor="#e7efff" width="100%" border="1" cellspacing="1" cellpadding="1" style="font-size:12px;">
		      		<tr>
					    <td colspan="10" align="center" valign="bottom">商家{$Think.session.UserInfo.boss}的库房货架情况</td>
                    </tr>
                    <tr>
                        <td bgcolor="#FF9933">初始化位置码</td>					
                        <td bgcolor="#FF9933">库房编码</td>
                        <td bgcolor="#FF9933">货架数量</td>
                        <td bgcolor="#FF9933">每个货架层数</td>
						<td bgcolor="#FF9933">初始化日期</td>
						<td bgcolor="#FF9933">货架情况描述</td>
						<td bgcolor="#FF9933">是否初始化</td>												
						<td bgcolor="#FF9933">修改</td>
                    </tr>
						<div id="list" >
                          <volist name="shelfList" id="vo">
                            <tr id="{$vo.id_tb_shelf}" onMouseOver="this.style.backgroundColor='#f7f7f7'"
							onmouseout="this.style.backgroundColor='transparent'" >
							  <td id="{$vo.id_tb_shelf}init" onClick="initLoc(this.id);" ><img src="__PUBLIC__/Images/limit.gif"/></td>							
							  <td id="{$vo.id_tb_shelf}depot_code">{$vo.depot_code}</td>
							  <td id="{$vo.id_tb_shelf}shelf_num">{$vo.shelf_num}</td>
                              <td id="{$vo.id_tb_shelf}shelf_layer">{$vo.shelf_layer}</td>                              
                              <td id="date">{$vo.date}</td>
                              <td id="describe">{$vo.describe}</td>	
                              <td id="{$vo.id_tb_shelf}it">{$vo.init}</td>								  						  
                              <td id="ed{$vo.id_tb_shelf}" onClick="editSlf(this.id)"><img src="__PUBLIC__/Images/edit.ico" alt="修改货架信息"/></td>
                            </tr>							
                          </volist>
                        </div>
					<tr>
                    <td align="center" colspan="8">		
					<?php
					if(isset($page)) echo $page;		
					?>	
                    </tr>
		  	</table>
		</if>
	
	<!--数据集显示结束-->
	</div>
	<!--显示数据列表结束-->
	
<!--显示位置码列表-->
	<div id="locList" style="overflow:scroll; text-align:center">
		<!--空记录开始-->
		<if condition="count($locList) elt 0">
		<br/><h3>位置码记录为空，没有初始化</h3>
		</if>
		<!--空记录结束-->	
		<!--数据集显示开始-->
		<if condition="count($locList) gt 0">
		<h3>位置码列表</h3>
			<table align="center" bgcolor="#e7efff" width="100%" border="1" cellspacing="1" cellpadding="1" style="font-size:12px;">
		      		<tr>
						<td colspan="10" align="center" valign="bottom">位置码列表</td>
                    </tr>
                    <tr>
                        <td bgcolor="#FF9933">序列号</td>					
                        <td bgcolor="#FF9933">位置码</td>
                        <td bgcolor="#FF9933">所属商家</td>
                    </tr>
						<div id="list" >
                          <volist name="locList" id="vo">
                            <tr id="{$vo.id_tb_location}" onMouseOver="this.style.backgroundColor='#f7f7f7'"
							onmouseout="this.style.backgroundColor='transparent'" > 
                              <td id="location_code">{$vo.id_tb_location}</td>							                            
                              <td id="location_code">{$vo.location_code}</td>
                              <td id="userid">{$vo.userid}</td>							  
                            </tr>							
                          </volist>
                        </div>
					<tr>
                    <td align="center" colspan="3">		
					<?php
					if(isset($page)) echo $page;		
					?>	
                    </tr>
		  	</table>
		</if>
	
	<!--数据集显示结束-->
	</div>
	<!--显示位置表列表结束-->	

</div>
<!--主页面结束-->
</body>
</html>
